<template>
  <div class="bg-white rounded-lg p-5 h-full">
    <div class="font-bold text-lg mb-4">行政处罚管理</div>

    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
    >
      <el-form-item prop="town">
        <el-input
          v-model="queryParams.town"
          placeholder="文书名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item prop="town">
        <el-input
          v-model="queryParams.town"
          placeholder="监督对象"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item prop="town">
        <el-input
          v-model="queryParams.town"
          placeholder="监督专业"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item prop="town">
        <el-input
          v-model="queryParams.town"
          placeholder="监督员"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
    </el-form>

    <div class="mb-4">
      <el-button type="primary" icon="" size="" @click="handleQuery"
        >搜索</el-button
      >
      <el-button icon="" size="" @click="resetQuery">重置</el-button>
      <el-button icon="" size="" @click="toEditPage">添加</el-button>
    </div>

    <el-table
      v-loading="loading"
      border 
      :data="dataList"
     
    >
      <el-table-column type="index" width="55" align="center" label="序号" />
      <el-table-column label="处罚类型" align="center" prop="A" />
      <el-table-column label="处罚对象" align="center" prop="B" />
      <el-table-column label="处罚对象类型" align="center" prop="C" />
      <el-table-column label="经营地址" align="center" prop="D" />
      <el-table-column label="监管员" align="center" prop="E" />
      <el-table-column label="处罚时间" align="center" prop="F" />
      <el-table-column label="文书名称" align="center" prop="G">
        <template #default="scope">
          <el-button type="text" @click="bookDetailBtn(scope.row)">{{
            scope.row.G
          }}</el-button>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        width="150px"
      >
        <template slot-scope="scope">
          <el-button @click="toDetailPage(scope.row)" type="text" size="small"
            >查看详情</el-button
          >
          <el-button
            size="mini"
            type="text"
           
            @click="handleDelete(scope.row)"
            v-hasPermi="['enterpriseInfo:info:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {
  listInfo,
  getInfo,
  delInfo,
  addInfo,
  updateInfo,
} from "@/api/zhangping/zpEnterpriseInfo";
import { categoryList } from "@/api/zhangping/category";

export default {
  name: "Info",
  dicts: [
    "enterprise_info_type",
    "health_certificate_status",
    "business_file_status",
    "enterprise_category",
  ],
 
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 一企一档表格数据
      dataList: [
       {}
      ],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        enterpriseName: null,
        creditCode: null,
        type: null,
        typeIdList: [],
        categoryIdList: [],
        category: null,
        town: null,
        townCode: null,
        addr: null,
        legalPerson: null,
        contactNumber: null,
        businessLicense: null,
        sanitaryPermit: null,
        sanitaryPermitDate: null,
        healthCertificateStatus: null,
        archivesStatus: null,
        lastUpdateTime: null,
        userId: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      detailForm: {},
      isEdit: false,
      editVisible: false,
      categoryList: [],
    };
  },
  created() {
    this.loading = false;
    //this.getList();
    // this.getCategoryList()
  },
  methods: {
    toDetailPage(row) {
      const obj = {
        path: "/health-care/supervise-document-detail",
        query: {
          id: "111",
        },
      };
      this.$router.push(obj);
    },
    toEditPage() {
      const path = "/health-care/supervise-document-edit";
      this.$router.push(path);
    },
    lookDetailBtn() {
      const obj = {
        path: "/healthCare/test/detail",
        query: {
          id: "111",
        },
      };
      this.$router.push(obj);
    },
    /** 查询一企一档列表 */
    getList() {
      this.loading = true;
      listInfo(this.queryParams).then((response) => {
        this.dataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        enterpriseName: null,
        creditCode: null,
        type: null,
        category: null,
        town: null,
        townCode: null,
        addr: null,
        legalPerson: null,
        contactNumber: null,
        businessLicense: null,
        sanitaryPermit: null,
        sanitaryPermitDate: null,
        healthCertificateStatus: null,
        archivesStatus: null,
        lastUpdateTime: null,
        userId: null,
        createId: null,
        createBy: null,
        createTime: null,
        updateId: null,
        updateBy: null,
        updateTime: null,
        delFlag: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.detailForm = {};
      this.isEdit = false;
      this.editVisible = true;
    },
    /** 修改按钮操作 */
    handleUpdate(row, type) {
      // this.reset();
      const id = row.id || this.ids;
      getInfo(id).then((response) => {
        this.detailForm = response.data;
        if (type == 1) {
          this.isEdit = true;
        } else {
          // 查看
          this.isEdit = false;
        }
        this.editVisible = true;
      });
    },
    /** 提交按钮 */
    submitForm(form, id) {
      if (id != null) {
        updateInfo(form).then((response) => {
          this.$modal.msgSuccess("修改成功");
          this.editVisible = false;
          this.getList();
        });
      } else {
        addInfo(form).then((response) => {
          this.$modal.msgSuccess("新增成功");
          this.editVisible = false;
          this.getList();
        });
      }
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除一企一档编号为"' + ids + '"的数据项？')
        .then(function () {
          return delInfo(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "enterpriseInfo/info/export",
        {
          ...this.queryParams,
        },
        `info_${new Date().getTime()}.xlsx`
      );
    },
    getCategoryList() {
      categoryList().then((response) => {
        this.categoryList = response.data;
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.app-container {
  .tableBtnListCss {
    margin-top: 10px;
    border-top: 1px solid #e0e0e0;
    padding-top: 10px;
  }
}
</style>
